package com.CrawlData;

import java.io.IOException;
import java.util.List;

import com.Crawlzongheng.ChapterPage;
import com.Crawlzongheng.IntroPage;
import com.Crawlzongheng.ReadPage;
import com.Crawlzongheng.UpdateList;
import com.Model.NovelChapterModel;
import com.Model.NovelInfoModel;
import com.Model.NovelReadMode;
import com.Util.ParseMD5;
import com.zonghengdb.ZongHengDB;

/**
 * Hello world!
 *
 */
public class App {
	public static void main(String[] args) throws IOException,
			InterruptedException {
		// 通过小说主页网址获得小说更新列表页的信息
		ZongHengDB db = new ZongHengDB();

		long time_before, time_after;
		time_before = System.currentTimeMillis();
		UpdateList updateList = new UpdateList(
				"http://book.zongheng.com/store.html");
		db.saveInfoUrls(updateList.getPageUrl(true));
		time_after = System.currentTimeMillis();
		System.out.println("采集更新列表页并且保存到数据库中所用时间 : "
				+ (time_after - time_before) / 1000 + "s");
		
		for (String novelPageUrl : updateList.getPageUrl(true)) {
			//
			long time_before1,time_after1;
			//简介页信息的采集和存储
			time_before1 = System.currentTimeMillis();
			IntroPage introPage = new IntroPage(novelPageUrl);
			NovelInfoModel bean = introPage.analyzer();
			db.updateNovelInfo(bean);
			
			//采集并存储章节页信息
			ChapterPage chapterPage = new ChapterPage(bean.getChapterListUrl());
			List<NovelChapterModel> list =  chapterPage.analyzer();
		
			db.saveNovelChapter(list, ParseMD5.parseStrToMD5(bean.getUrl()));
			//采集并存储小说内容信息
			for(NovelChapterModel index : list){
				ReadPage readPage = new ReadPage(index.getUrl());
				
				
				NovelReadMode beanRead = readPage.analyzer();
				beanRead .setChapterId(index.getChapterId());
				beanRead .setChapterTime(index.getChapterTime());
				db.saveNovelRead(beanRead);
			}
			time_after1 = System.currentTimeMillis();
			System.out.println("采集小说---"+bean.getName() + " 全部内容所花的时间是:" + (time_after1-time_before1)/1000 + "s");
		}
		time_after = System.currentTimeMillis();
		System.out.println("获取所有数据所用时间 : "+ (time_after - time_before) / 1000 + "s");
		
		
		
	}

}
